<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>租户审核</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
</head>
<body>
<div class="dashboard-container" id="device-app">
    <div class="container">
        <div class="tableBar">
            <div class="tableLab">
                租户用户名<el-input v-model="conditions.name" placeolder="输入租户用户名" style="width: 250px" clearable></el-input>
                租户Key<el-input v-model="conditions.accessKey" placeolder="输入租户Key" style="width: 250px" clearable></el-input>
                <el-button  type="primary" icon="el-icon-search" @click="handleQuery()">搜索</el-button>
            </div>
        </div>
        <el-table  :data="pagination.tableData"  stripe  class="tableBox" >
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column  prop="name" label="租户用户名"  /></el-table-column>
            <el-table-column prop="accessKey"  label="租户Key" ></el-table-column>
            <el-table-column prop="companyName"  label="公司名称" ></el-table-column>
            <el-table-column prop="companyCode"  label="执照编码" ></el-table-column>
            <el-table-column prop="phone"  label="手机号" ></el-table-column>
            <el-table-column prop="enable"  label="是否可用" >
                <template slot-scope="scope">
                    <span v-if="scope.row.enable==1"><el-tag type="success">可用</el-tag></span>
                    <span v-if="scope.row.enable==2"><el-tag type="danger">不可用</el-tag></span>
                </template>
            </el-table-column>
            <el-table-column prop="description"  label="描述" ></el-table-column>
            <el-table-column prop="auditStatus"  label="状态" >
                <template slot-scope="scope">
                    <span v-if="scope.row.auditStatus==0"><el-tag type="info">待审核</el-tag></span>
                    <span v-if="scope.row.auditStatus==1"><el-tag type="success">通过</el-tag></span>
                    <span v-if="scope.row.auditStatus==2"><el-tag type="danger">不通过</el-tag></span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="160" align="center">
                <template slot-scope="scope">
                    <el-button type="text" size="small" class="blueBug" @click="checkYes(scope.row.id)">通过</el-button>
                    <el-button type="text" size="small" class="blueBug" @click="checkNo(scope.row.id)">不通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pagination.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pagination.counts"
                @size-change="handleSizeChange"
                :current-page.sync="pagination.page"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
<script src="../../plugins/vue/vue.js"></script>
<script src="../../plugins/element-ui/index.js"></script>
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/tenant.js"></script>
<script type="text/javascript">
    new Vue({
        el: '#device-app',
        data() {
            return {
                action: '',
                type: '',
                pagination: {
                    tableData: [],
                    page: 1,
                    pageSize: 10,
                    counts:0,
                },
                conditions:{
                    name:'',
                    accessKey:'',
                    auditStatus:0
                }
            }
        },
        methods: {
            async init() {
                const params = {
                    page: {
                        current: this.pagination.page,//当前页码
                        size: this.pagination.pageSize,//每页大小
                    },
                    name: this.conditions.name ? this.conditions.name : undefined,
                    accessKey: this.conditions.accessKey ? this.conditions.accessKey : undefined,
                    auditStatus:0
                };
                await findTenantPage(params).then(res => {
                    console.log(params);
                    if (String(res.code) === '200') {
                        this.pagination.tableData = res.data.records;
                        this.pagination.counts = res.data.total;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },
            //审核通过
            checkYes(st) {
                checkYes(st).then(res => {
                    if (res.code === 200) {
                        this.$message.success('操作成功！');
                        this.handleQuery()
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            //审核不通过
            checkNo(st) {
                checkNo(st).then(res => {
                    if (res.code === 200) {
                        this.$message.success('操作成功！');
                        this.handleQuery()
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            //分页相关全部操作
            handleSelectionChange(val) {
                let checkArr = [];
                val.forEach((n) => {
                    checkArr.push(n.id)
                });
                this.checkList = checkArr
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val;
                this.init()
            },
        },
        created() {
            this.init();
        }
    })
</script>
</body>
</html>